
   $(function(){
       //全局变量
       var global={};
       global.oMsg= $("#js_msg");
       //实例化
       var socket = io();
       //事件
       socket.emit("user join",{
           user: user,
           sid:sid
       })
       //监听
       socket.on('system',function(ret){
           var _html ="";
           if("welcome" == ret.type){
               _html = '<li class="list-group-item"><span class="label label-primary">system</span><mark>'+ ret.time+ '</mark>: Welcome.'+ ret.text +'</li>';
           }else{
               _html = '<li class="list-group-item"><span class="label label-warning">system</span><mark>'+ ret.time+ '</mark>: Bye.'+ ret.text +'</li>';
           }
           global.oMsg.find(".list-group").prepend(_html);
       });
       socket.on('to' + user, function(ret) {
           console.log("tosomeBODY:::"+ret);
           var _html = '<li class="list-group-item"><span class="label label-danger">system</span><mark>'+ ret.time+ '</mark>: '+ ret.text +'</li>';
           global.oMsg.find(".list-group").prepend(_html);
           socket.emit("empty");

           alert(ret.text);
           setTimeout(function(){
               window.location.href="/users/logout?type=1"
           },0);
       })

   });


